package com.ceuer.demo.thread;

//多个线程同时操作同一个对象
public class Demo2Muil implements Runnable{
	//票数
	private int ticketNum=10;
	
	public static void main(String[] args) {
		Demo2Muil demo2Muil=new Demo2Muil();
		new Thread(demo2Muil,"张三").start();
		new Thread(demo2Muil,"李四").start();
		new Thread(demo2Muil,"黄牛党").start();
	}
	
	@Override
	public void run() {
		while (true){
			if(ticketNum<0) break;
			//模拟延时
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+"--->拿到了第"+ticketNum--+"张票~");
		}
	}
}
